package com.chenglu.android.couponcenter.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chenglu.android.R;
import com.chenglu.android.common.utils.BigDecimalUtil;
import com.chenglu.android.common.utils.Utils;
import com.chenglu.android.couponcenter.CouponUtils;
import com.chenglu.android.goodsinfo.bean.ShopCouponPage;
import com.chenglu.android.goodsinfo.infoutils.GoodsInfoUtils;

import java.util.List;

/**
 * @author: lyj
 * @Created: by Copyright 2023 6 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description：
 */
public class CouponCenterAdapter extends BaseQuickAdapter<ShopCouponPage.Data.Records, BaseViewHolder> {

    Context mContext;

    public CouponCenterAdapter(Context context, @Nullable List<ShopCouponPage.Data.Records> data) {
        super(R.layout.item_coupun_center, data);
        this.mContext = context;
    }

    boolean isShow = true;

    @Override
    protected void convert(@NonNull BaseViewHolder helper, ShopCouponPage.Data.Records item) {

        if (item == null) {
            return;
        }
        helper.setText(R.id.tv_coupon_name, item.getShopsName());


//        helper.setText(R.id.tv_tag_name, item.getShopsName()); //店铺名称
        if(item.getMinMoney()==0.0){
            helper.setText(R.id.tv_coupon_money, "无门槛可用");
        }else {
            helper.setText(R.id.tv_coupon_money, "满" + Utils.doubleTrans2(item.getMinMoney()) + "可用");
        }

        helper.setText(R.id.tv_price, Utils.doubleTrans2(item.getCouponAmount()) + "");
        //折扣
        String mul = BigDecimalUtil.mul(item.getCouponPercentage(), "10");
        helper.setText(R.id.tv_discount, Utils.formatZeroNumber(mul));

        //满减
        LinearLayout lldiscount = helper.getView(R.id.ll_discount);
        LinearLayout llprcie = helper.getView(R.id.ll_price);
        if(item.getCouponUseType()==1){
            lldiscount.setVisibility(View.GONE);
            llprcie.setVisibility(View.VISIBLE);
        }else {
            lldiscount.setVisibility(View.VISIBLE);
            llprcie.setVisibility(View.GONE);
        }



        if (item.getIsReceive()) {
            //已领取
            helper.setText(R.id.tv_receive_now, "去使用");

        } else {
            //立即领取
            helper.setText(R.id.tv_receive_now, "立即领取");
        }




//        helper.setText(R.id.tv_date_limit, item.getUseStartTime() + "-" + item.getUseEndTime()); //时间限制
//         CheckBox checkBox =  helper.getView(R.id.cb_coupou_item);
//        ImageView checkBox = helper.getView(R.id.cb_coupou_item);

        TextView tvTag = helper.getView(R.id.tv_tag_category);

        CouponUtils.setCoupouTag(tvTag, item.getShopsTypeId());

        RecyclerView recyclerView = helper.getView(R.id.rv_item_shop);
        CouponItemAdapter couponItemAdapter = new CouponItemAdapter(mContext, item.getGoodsList());
        LinearLayoutManager gridLayoutManager = new LinearLayoutManager(mContext, RecyclerView.HORIZONTAL, false);
        recyclerView.setLayoutManager(gridLayoutManager);
        recyclerView.setAdapter(couponItemAdapter);

        couponItemAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

                    if (couponItemAdapter.getData().get(position).getShopsTypeId() == 2) {
                        GoodsInfoUtils.goodsRestantInfo(mContext, couponItemAdapter.getData().get(position).getId(), couponItemAdapter.getData().get(position).getShopsTypeId());
                    } else {
                        GoodsInfoUtils.goodsInfo(mContext, couponItemAdapter.getData().get(position).getId()
                                , couponItemAdapter.getData().get(position).getShopsTypeId());
                    }

            }
        });

//        if(item.isTagSelect()){
//            helper.setGone(R.id.ll_show_des,true);
//            helper.setBackgroundRes(R.id.iv_down,R.drawable.icon_refund_up);
//        }else {
//            helper.setGone(R.id.ll_show_des,false);
//            helper.setBackgroundRes(R.id.iv_down,R.drawable.icon_refund_down);
//        }


        helper.addOnClickListener(R.id.tv_receive_now);


//         if(item.getUseStatus() == 1 ){
//             checkBox.setVisibility(View.VISIBLE);
//             checkBox.setBackground(mContext.getResources().getDrawable(R.drawable.list_checkbox_select));
//             LogUtils.d("gaodeadapter----"+ item.getUseStatus());
//         }else {
//            checkBox.setVisibility(View.GONE);
//             LogUtils.d("gaodeadapter----"+ item.getUseStatus());
//         }


    }




    //先声明一个int成员变量,若为0默认显示第一个
    private int thisPosition = 1001;

    //点击选择item
    private int thisTagPosition = 1002;

    public int getThisTagPosition() {
        return thisTagPosition;
    }

    public void setThisTagPosition(int thisTagPosition) {
        this.thisTagPosition = thisTagPosition;
    }

    //再定义一个int类型的返回值方法
    public int getthisPosition() {
        return thisPosition;
    }

    //   传入点击的位置
    public void setThisPosition(int thisPosition) {
        this.thisPosition = thisPosition;
        notifyDataSetChanged();
    }
}
